<?php 
 class ColumnsModel extends Model{

 	public $table = 'columns';
 	public $validate = array(
 		array('title','nonull','类名不能为空',2,3),
 		array('title','maxlen:20','类名最大长度不能超过20个',2,3),
 		
 		);

 		public function get_data($where=NULL){
 			
 			return $this->where($where)->all();
 		}


 	/**
 	 * [add_data 添加类的方法]
 	 */
 		public function add_data(){
 		return $this->add();

 	}

/**
 * [del_data 删除]
 * @return [type] [description]
 */
 	public function del_data($cnid){
 		// getField 寻找某条数据的某个字段
 		$data = $this->where(array('pid'=>$cnid))->getField('cnid');

 		if($data){
 			$this->error = '请先删除该分类下的子集';
 			return false;

 		}
 		$this->where(array('cnid'=>$cnid))->delete();
 	}

 	/**
 	 * [find_data 找一条数据]
 	 * @param  [type] $where [description]
 	 * @return [type]        [description]
 	 */
 		public function find_data($where=null){
 			return $this->where($where)->find();
 		}

 		public function update_data($where){
 			$this->where($where)->save();
 		}



 	public function ajax_change_stat(){
 		$cid = Q('post.cid',0,'intval');
 		$stat = Q('post.stat',0,'intval');
 		$type = Q('post.type');

 		switch ($type) {
 			case 'list':
 				if ($stat) {
 					$this->where(array('cid'=>$cid))->update(array('is_listhtml'=>0));
 				}else{
 					$this->where(array('cid'=>$cid))->update(array('is_listhtml'=>1));
 				}
 				
 				break;
 			case 'arc':
 				if ($stat) {
 					$this->where(array('cid'=>$cid))->update(array('is_archtml'=>0));
 				}else{
 					$this->where(array('cid'=>$cid))->update(array('is_archtml'=>1));
 				}
 				
 				break;
 			case 'show':
 				if ($stat) {
 					$this->where(array('cid'=>$cid))->update(array('is_show'=>0));
 				}else{
 					$this->where(array('cid'=>$cid))->update(array('is_show'=>1));
 				}
 				
 				break;
 			
 			
 		}
 	}



 }



 ?>